import cv2
from numpy import ndarray


def light_balance(cv_image) -> ndarray:
    """
    亮度均衡
    将图片转为YUV颜色空间进行亮度通道直方图均衡化,达到颜色亮度均衡
    params:
        cv_image: ndarray
    """
    # 将图像转换到 YUV 颜色空间
    yuv_image = cv2.cvtColor(cv_image, cv2.COLOR_BGR2YUV)
    # 对 Y 通道（亮度通道）进行直方图均衡化
    yuv_image[:, :, 0] = cv2.equalizeHist(yuv_image[:, :, 0])
    # 将 YUV 图像转换回 BGR 颜色空间
    equalized_image = cv2.cvtColor(yuv_image, cv2.COLOR_YUV2BGR)
    return equalized_image


